package org.tlipoca.smusersubscribe.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.genntii.smdomain.entity.UserSubscribe;

import java.util.ArrayList;

@Mapper
public interface UserSubscribeMapper extends BaseMapper<UserSubscribe> {
    
    @Select("select * from User_Subscribe where subscriber_user_id = #{userId};")
    ArrayList<UserSubscribe> selectUserSubscribeListByUserId(Long userId);

    @Delete("delete from User_Subscribe where subscriber_user_id = #{subscriberId} and user_id = #{userId};")
    void deleteSubscribeUser(Long subscriberId, Long userId);

    @Delete("delete from User_Subscribe where user_id = #{subscriberId} and channel_id = #{channelId};")
    void deleteSubscribeChannel(Long subscriberId, Long channelId);

    @Select("select COUNT(*) from User_Subscribe where user_id = #{userId} and channel_id = 0")
    Integer getSubscribeNum(Long userId);

    @Select("select count(*) from User_Subscribe where subscriber_user_id  = #{userId} and channel_id = 0")
    Integer getSubscribedNum(Long userId);

    @Select("select * from User_Subscribe where user_id = #{userId} and channel_id = 0 and subscriber_user_id = #{subscriberId}")
    UserSubscribe userSubscribed(Long userId,Long subscriberId);

    @Select("select * from User_Subscribe where user_id = #{userId} and subscriber_user_id = 0 and channel_id = #{channelId}")
    UserSubscribe channelSubscribed(Long userId, Long channelId);

    @Select("select * from User_Subscribe where user_id = #{userId} and channel_id = 0;")
    ArrayList<UserSubscribe> subscribe8u(Long userId);

    @Select("select *from User_Subscribe where user_id = #{userId} and subscriber_user_id = 0")
    ArrayList<UserSubscribe> subscribe8c(Long userId);

}
